package com.example.xui;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;

import android.content.Intent;
import android.graphics.Color;
import android.nfc.Tag;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.xui.Way.changStatusIconCollor;
import com.xuexiang.xui.XUI;
import com.xuexiang.xui.widget.flowlayout.FlowTagLayout;

import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import kotlin.jvm.internal.Ref;

public class Interest extends AppCompatActivity {
    List<String> list=new ArrayList<>();
    List<Integer> l=new ArrayList<>();
    private ImageView imageView;
    private ImageView imageView1;
    private FlowTagLayout flowTagLayout;
    private String sno;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        XUI.initTheme(this);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interest);
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setNavigationBarColor(Color.TRANSPARENT);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        changStatusIconCollor changStatusIconCollor=new changStatusIconCollor();
        changStatusIconCollor.changStatusIconCollor1(getWindow(),true);
        init();
    }

    public void init(){
        sno=getIntent().getStringExtra("sno");
        Toast.makeText(Interest.this,"sno="+sno,Toast.LENGTH_SHORT).show();
        flowTagLayout=findViewById(R.id.flowtaglayout);
        imageView=findViewById(R.id.imageView34);
        imageView1=findViewById(R.id.imageView37);
        flowTagLayout.setOnTagSelectListener(new FlowTagLayout.OnTagSelectListener() {

                 @Override
                 public void onItemSelect(FlowTagLayout parent, int position, List<Integer> selectedList) {
                     list.add(parent.getSelectedItem());
                     Log.i("tag","tag="+list.get(0));
                 }
             });

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Thread(){
                    @Override
                    public void run() {
                        super.run();
                        RequestParams params = new RequestParams("http://10.138.87.49:8080/user/userupdatehobby");
                        params.addHeader("Content-Type","application/x-www-form-urlencoded");
                        params.addBodyParameter("userID",sno);
                        params.addBodyParameter("userHobby",list.get(0));
//                        Toast.makeText(Interest.this,"sno="+list.get(0),Toast.LENGTH_SHORT).show();
                        Log.i("tag","dss="+list.get(0));
                        x.http().post(params, new Callback.CacheCallback<String>() {
                            @Override
                            public void onSuccess(String result) {
                                if(result.equals("success")) {
                                    Intent intent=new Intent(Interest.this,Shezhi.class);
                                    intent.putExtra("userID",sno);
                                    startActivity(intent);
                                    finish();
                                    Toast.makeText(Interest.this, "修改成功", Toast.LENGTH_SHORT).show();
                                }
                            }

                            @Override
                            public void onError(Throwable ex, boolean isOnCallback) {
                                Toast.makeText(Interest.this,"网络请求错误",Toast.LENGTH_SHORT).show();
                                Log.i("sd",params.toString());
                            }

                            @Override
                            public void onCancelled(CancelledException cex) {
                                Toast.makeText(Interest.this,"请求已取消",Toast.LENGTH_SHORT).show();
                            }

                            @Override
                            public void onFinished() {

                            }

                            @Override
                            public boolean onCache(String result) {
                                return false;
                            }
                        });
                    }
                }.start();
                Toast.makeText(Interest.this,"tt="+list.get(0).toString(),Toast.LENGTH_SHORT).show();

                finish();
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        Toast.makeText(Interest.this,"onPause1",Toast.LENGTH_SHORT).show();
    }
}
